<template>
  <div>
    
		 
	  <el-form-item label="检测关键词:">
	    <!--<el-select v-model="wordIndex" placeholder="请选择关键词" @change = "selectChange()">
	      <el-option  v-for="(item,index) in list" :key="index" :label="item.wordName" :value="index"></el-option>
	    </el-select>-->
	    
	    <el-select v-model="value5" multiple placeholder="请选择关键词"  @change = "selectChange()">
		    <el-option
		      v-for="(item,index) in list"
		      :key="index"
		      :label="item.wordName"
		      :value="index">
		    </el-option>
		  </el-select>
	    
	  </el-form-item>
					  
		  	
  </div>
</template>

<script>
import API from "@/api"
export default {
  name: 'Check',
  data () {
    return {
       list:[],
       wordIndex:'',
       imgurl:'',
       value5: [],
    }
  },
  mounted: function () {
  	this.getList()
  },
   methods: {
   	getList(){
	  	API.setting.getList(API.header.getCookie("token")).then(({data}) => {
	       if(data.code=='0'){
						this.list = data.data;
	       }else{
						this.$message.error(data.msg);
	       }
      })
	  },
	  selectChange(){
//	  	console.error(this.value5)
	  	sessionStorage.setItem("urlWordId",JSON.stringify(this.value5))
//	  	console.error('selectevent',this.list[this.wordIndex]);
	  	var indexArr = this.value5;
	  	var selectArr = [];
	  	for(var i=0;i<indexArr.length;i++){
	  		selectArr.push(this.list[indexArr[i]])
	  	}
//	  	this.$emit('selectevent',selectArr);
//	  		console.error(selectArr)
	  	var newArr = {"wordTxt":"","wordName":"","wordId":""};
	  	for(var i=0;i<selectArr.length;i++){
	  		newArr.wordName += selectArr[i].wordName + " ";
	  		newArr.wordId += selectArr[i].wordId + " ";
	  		if(selectArr[i].wordTxt.substr(selectArr[i].wordTxt.length-1,1) == " " || selectArr[i].wordTxt.substr(selectArr[i].wordTxt.length-1,1) == " " ){
	  			newArr.wordTxt += selectArr[i].wordTxt.substr(0,selectArr[i].wordTxt.length-1) + " ";
	  		}else{
	  			newArr.wordTxt += selectArr[i].wordTxt + " ";
	  		}
//	  		newArr.wordTxt = newArr.wordTxt.replace(new RegExp('，','g'),',')
	  	}
	  	newArr.wordTxt = newArr.wordTxt.substr(0,newArr.wordTxt.length-1);
	  	newArr.wordName = newArr.wordName.substr(0,newArr.wordName.length-1);
	  	newArr.wordId = newArr.wordId.substr(0,newArr.wordId.length-1);
	  	this.$emit('selectevent',newArr);
//	  	console.info(newArr)
	  }
	}
  
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

	
</style>
